package design_patterns_and_best_practices_in_java;

interface CoffeeMachineFacade {
    CoffeeCup serveCoffee() throws InterruptedException;
}

interface CoffeeGrinder {
    void startGrinding();

    GroundCoffee stopGrinding();
}

interface CoffeeMaker {
    void pourWater(Water water);

    void placeCup(CoffeeCup cup);

    void startBrewing(GroundCoffee groundCoffee);

    CoffeeCup finishBrewing();
}

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/11/14 21:43
 */
public class Chapter4FadeMode {
    public static void main(String[] args) throws InterruptedException {
        CoffeeMachineFacade facade = new SupperstarCoffeeMachine();
        facade.serveCoffee();
    }
}

class GroundCoffee {
}

class Water {
}

class CoffeeCup {
}

class SuperstartCoffeeGrinder implements CoffeeGrinder {

    @Override
    public void startGrinding() {
        System.out.println("Grinding...");
    }

    @Override
    public GroundCoffee stopGrinding() {
        System.out.println("Done grinding");
        return new GroundCoffee();
    }
}

class SuperstarCoffeeMaker implements CoffeeMaker {

    @Override
    public void pourWater(Water water) {
        System.out.println("Pouring water...");
    }

    @Override
    public void placeCup(CoffeeCup cup) {
        System.out.println("Placing the cup");
    }

    @Override
    public void startBrewing(GroundCoffee groundCoffee) {
        System.out.println("Brewing...");
    }

    @Override
    public CoffeeCup finishBrewing() {
        System.out.println("Done brewing. Enjoy!");
        return null;
    }
}

class SupperstarCoffeeMachine implements CoffeeMachineFacade {

    @Override
    public CoffeeCup serveCoffee() throws InterruptedException {
        CoffeeGrinder grinder = new SuperstartCoffeeGrinder();
        CoffeeMaker brewer = new SuperstarCoffeeMaker();
        CoffeeCup cup = new CoffeeCup();
        grinder.startGrinding();
        Thread.sleep(500);
        brewer.placeCup(cup);
        brewer.pourWater(new Water());
        brewer.startBrewing(grinder.stopGrinding());
        Thread.sleep(1000);
        return brewer.finishBrewing();
    }
}